
/*
 * Name: tcpclient
 * Version: 0.1.1
 * Description: A simple program to send arbitrary packets
 * on a TCP connection.
 */

#include "balzebub.h"

using namespace bzbterm;
using namespace bzbnet;
using namespace bzbio;


int main(int argc, char const *argv[]) {

	std::string hostname;
	std::string service;
	std::string packet;

	println(fg::bright_yellow, "Hostname:");
	getline(std::cin, hostname);
	println(fg::bright_yellow, "Port or Service:");
	getline(std::cin, service);

	println(fg::bright_yellow, "Message (QUIT to end):");
	std::string line;
	do {
		getline(std::cin, line);
		if(line != "QUIT") {
			packet.append(line);
			packet.append("\n");
		}
	} while(line != "QUIT");
	
	TCPSocket socket;

	println(fg::green, "Connecting to ", hostname, "...");
	socket.connect(hostname, service);

	println(fg::green, "Sending message...");
	socket.send(packet);

	println(fg::green, "Waiting for response..");
	auto data = socket.recv();

	println(fg::bright_yellow, "Response:");
	println(fg::cyan, std::string(&data[0]));

	socket.close();

	return 0;
}
